//
//  LS_ShowLoadView.m
//  nanchangNews
//
//  Created by 刘文超 on 2019/10/25.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "LS_ShowLoadView.h"

@interface LS_ShowLoadView()

@end
@implementation LS_ShowLoadView
+ (LS_ShowLoadView *)sharedLS_ShowLoadView {
   static LS_ShowLoadView *sharedLS_ShowLoadView = nil;
   static dispatch_once_t onceToken;
   dispatch_once(&onceToken, ^{
   sharedLS_ShowLoadView = [[self alloc] init];
   });
   return sharedLS_ShowLoadView;
}

-(void)showLoadView
{
    UIView *bgView = [[UIView alloc]initWithFrame:UIScreen.mainScreen.bounds];
    [[UIApplication sharedApplication].keyWindow addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
          
    //3.0版本
    CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer layer];
    replicatorLayer.bounds          = CGRectMake(0, 0, 100, 100);
    replicatorLayer.cornerRadius    = 10.0;
    replicatorLayer.position        =  CGPointMake([UIScreen mainScreen].bounds.size.width/2, [UIScreen mainScreen].bounds.size.height/2);
    replicatorLayer.backgroundColor = [UIColor lightGrayColor].CGColor;
    
    [bgView.layer addSublayer:replicatorLayer];
    
    
    CALayer *dotLayer        = [CALayer layer];
    dotLayer.bounds          = CGRectMake(0, 0, 15, 15);
    dotLayer.position        = CGPointMake(15, replicatorLayer.frame.size.height/2 );
    dotLayer.backgroundColor = UIColor.blueColor.CGColor;
    dotLayer.cornerRadius    = 7.5;
    dotLayer.transform = CATransform3DMakeScale(0, 0, 0);
    replicatorLayer.instanceCount = 3;
    replicatorLayer.instanceTransform = CATransform3DMakeTranslation(replicatorLayer.frame.size.width/3, 0, 0);
    replicatorLayer.instanceDelay = 1.0/3;
    [replicatorLayer addSublayer:dotLayer];
    
    UILabel *label = [[UILabel alloc]init];
    [bgView addSubview:label];
    label.font = [UIFont systemFontOfSize:18];
    label.textColor = UIColor.blueColor;
    label.text = @"加载中";
    label.textAlignment = NSTextAlignmentCenter;
    label.frame =  CGRectMake([UIScreen mainScreen].bounds.size.width/2-50, [UIScreen mainScreen].bounds.size.height/2+25, 100, 25);
    
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    animation.duration    = 1.0;
    animation.fromValue   = @1;
    animation.toValue     = @0;
    animation.repeatCount = MAXFLOAT;
    [dotLayer addAnimation:animation forKey:nil];
   
    
    CABasicAnimation *labelAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    labelAnimation.duration    = 1.3;
    labelAnimation.fromValue   = @1;
    labelAnimation.toValue     = @0.6;
     labelAnimation.byValue     = @1;
    labelAnimation.repeatCount = MAXFLOAT;
    [label.layer addAnimation:labelAnimation forKey:nil];
    
}


-(void)removeSubView
{
//    [UIApplication.sharedApplication.keyWindow removeFromSuperview];
}

@end
